clear all
set more off 
version 12.0
set trace off
cap log close
pause off

* Set path
if "`c(username)'"=="YOUR USER NAME"{
	global home "YOUR PATH TO REPLICATION FOLDER"
}
	global code "$home/Code"
	global data "$home/Data"
	global output "$home/Output"

set scheme s1color

* Load custom regression table formatting do files
include "$code/Balance_reg_fe.do"
include "$code/Balance_reg.do"

/////////
// Figure 1 Childcare hours trends/descriptives
/////////
{
// Data prep
use "$data/indivs_merge.dta", clear
replace month=729 if month==800 // had split October into two FEs, use 800 as placeholder value
gen monum=month
gen period=wave
replace period=1 if period==2 & monum==726
replace period=2 if period==3 & post==0
lab def pd 0 "Feb" 1 "May-July" 2 "Aug-Oct 11" 3 "Oct 12-Nov" 4 "Jan-Mar"
la val period pd

gen kidcount=kids_count
replace kidcount=4 if kidcount>4
lab def countkid 0 "0" 1 "1" 2 "2" 3 "3" 4 "4+"
lab values kidcount countkid
replace childcare_hr_pre=0 if missing(childcare_hr_pre) & wave==4
su s4_chldcrhrs_children if resp==1 & wave==4,d
foreach v of varlist childcare_hr s4_chldcrhrs_children s4_chldcrhrs_outsidehh {
	replace `v'=0 if missing(`v')
	replace `v'=140 if `v'>140 & !missing(`v')
	replace `v'=0 if kidcount==0
}
su s4_chldcrhrs_children if resp==1 & wave==4 & kidcount>1,d
egen childcare_hr_precl=max(childcare_hr_pre),by(id individual)
replace childcare_hr=childcare_hr_precl if !missing(childcare_hr_precl) & wave==0
gen childcare_hr2=childcare_hr
replace childcare_hr2=112 if childcare_hr2>112 & !missing(childcare_hr2)

// Respondent hours by school closures
local white 	plotregion(color(white)) graphregion(color(white)) bgcolor(white)	
preserve
keep if resp==1
keep if !missing(trt_ctl)
keep if inlist(wave,0,1,2,3,4)
collapse (mean) ccl7=childcare_hr (sd) sd=childcare_hr (count) n=childcare_hr, by(gender period)
gen hi=ccl7 + invttail(n-1,0.025)*(sd/sqrt(n))
gen lo=ccl7 - invttail(n-1,0.025)*(sd/sqrt(n))
	
twoway 	(line ccl7 period if gender==1, color(black)) ///
		(rcap hi lo period if gender==1, color(black)) ///
		(line ccl7 period if gender==0, color(gs8) lpattern(dash)) ///
		(rcap hi lo period if gender==0, color(gs8)) ///
		, `white' ///	
		xtitle("Survey period", size(medsmall)) ytitle("Hours of childcare in last 7 days", size(medsmall)) ///
		ylabel(0(10)80, labsize(medsmall) angle(0) grid glcolor(gs15)) ///
		xlabel(, valuelabels labsize(medsmall) angle(10)) ///
		text(0 0.3 "Schools open" , color(black) size(medsmall) placement(n)) ///
		text(0 1.5 "|      Schools closed      |" , color(black) size(medsmall) placement(n)) ///
		text(0 2.9 "Schools partially" "reopen" , color(black) size(medsmall) placement(n)) ///
		text(0 3.8 "Schools fully" "reopen" , color(black) size(medsmall) placement(n)) ///
		text(55 1.3 "Women" , color(black) size(medsmall) placement(e)) ///
		text(36 1.3 "Men" , color(gs8) size(medsmall) placement(n)) ///
		legend(off)
graph export "$output/Graphs/childcare_resp_period_sex_anl.pdf", replace
graph export "$output/Graphs/childcare_resp_period_sex_anl.tif", replace
restore

// All providers, wave 4
preserve
keep if wave==4 | wave==3
eststo clear
eststo: reg childcare_hr i.(gender resp ishead)##i.kidcount if age>17 & kidcount>0, cluster(id)
	su childcare_hr if gender==0 & resp==0 & ishead==0 & kidcount==1
	estadd scalar Mean = r(mean)
esttab using "$output/Tables/childcarehrs_demog.tex", ///
	drop(_cons) ///
	scalars("Mean Mean, Male non-resp non-head 0 kids") /// 
	star(* 0.10 ** 0.05 *** 0.01) ///
	addnote("SEs clustered at household level.") ///
	se(2) varwidth(45) num nonotes label replace booktabs nobaselevels obs b(2) f end( \\ )

keep if wave==4
keep if  !missing(trt_ctl)
egen adult_carehrs=sum(childcare_hr), by(id)
egen child_carehrs=max(s4_chldcrhrs_children), by(id)
egen outside_carehrs=max(s4_chldcrhrs_outsidehh), by(id)
su provided_chldcr_ if kidcount>1 & age>4 & age<18
su provided_chldcr_ if any_ygkid==1 & age>4 & age<18
su provided_chldcr_ if any_ygkid==0 & age>4 & age<18
su provided_chldcr_ if grade39==1 & kidcount>1
su provided_chldcr_ if grade39==1 & any_ygkid==1
su provided_chldcr_ if grade39==1 & any_ygskl==1
su s3_hh_childcare_a if grade39==1 & provided_chldcr_==1 & kidcount>1
su s3_hh_childcare_a if grade39==1 & provided_chldcr_==1 & any_ygkid==1
su s3_hh_childcare_a if grade39==1 & provided_chldcr_==1 & any_ygskl==1
bys gender: su provided_chldcr_ if grade39==1  & kidcount>1
bys gender: su s4_chldcrhrs_children if grade39==1  & kidcount>1

keep if resp==1
su childcare_hr adult_carehrs child_carehrs outside_carehrs
replace child_carehrs=0 if kidcount<2
egen total_carehrs=rowtotal(adult_carehrs child_carehrs outside_carehrs)
gen perchild_carehrs=total_carehrs/kidcount
gen child_care_perkid=child_carehrs/(kidcount-1)
su child_care_perkid if kidcount>1,d
replace perchild_carehrs=0 if kidcount==0
reg childcare_hr kidcount

ta outside_care if kids==1
ta extraadults if kids==1
su adult_carehrs childcare_hr if kids==1
su child_carehrs if kids_count>1
bys gender: su childcare_hr if kids==1

bys kidcount: egen childcare_step_gender = mean(adult_carehrs)
bys kidcount: egen childcare_step_gender1 = mean(childcare_hr)
bys kidcount: egen childcare_step_gender2 = mean(child_carehrs)
bys kidcount: egen childcare_step_gender3 = mean(outside_carehrs)

local white 	plotregion(color(white)) graphregion(color(white)) bgcolor(white)
twoway	(line childcare_step_gender kidcount, color(black)) ///
		(line childcare_step_gender1 kidcount, lpattern(longdash) color(black)) ///
		(line childcare_step_gender2 kidcount, lpattern(dash_dot) color(black)) ///
		(line childcare_step_gender3 kidcount, lpattern(dot) color(black)) ///	
		, `white' ///
		ytitle("Hours of childcare in last 7 days", axis(1) size(medsmall) ) ///
		ylabel(0(10)80, labsize(medsmall) angle(0) grid glcolor(gs15)) ///
		yscale(axis(1) lcolor(black) ) /// 
		xtitle("Number of household children", size(medsmall)) ///
		xlabel(1(1)4, valuelabels labsize(medsmall)) ///
		text(72 2 "All household adults" , color(black) size(medsmall) placement(e)) ///
		text(35.5 1 "Respondent" , color(black) size(medsmall) placement(e)) ///
		text(18.5 2 "All household children" , color(black) size(medsmall) placement(e)) ///
		text(4.5 2 "Non-household members" , color(black) size(medsmall) placement(e)) ///
		legend(off)  
graph export "$output/Graphs/childcare_hhmembers_w4_anl.pdf", replace
graph export "$output/Graphs/childcare_hhmembers_w4_anl.tif", replace
restore
}

/////////
// Figure 2 HH ag labor trends/descriptives
/////////
{
* This code goes back to the raw RRPS data to include values from additional survey waves
use "$data/KEN_2020_COVIDRS_v07_M_STATA14/hh.dta", clear
merge 1:m hhid wave using "$data/KEN_2020_COVIDRS_v07_M_STATA14/hh_adult.dta",  nogen
keep if wave<=6

egen agever	=max(s4_q1_agactivity_1),by(hhid)
egen adultaghrs=sum(agri_hrs),by(hhid wave)
replace s4_q2_hours_allchild=0 if missing(s4_q2_hours_allchild)
keep if s2_q15b_schoolchildren>0
keep if is_respondent==1
keep if s4_q1_agactivity_1==1
gen childag=s4_q2_hours_allchild>0
gen s4_q2_hours_allchild_ag=s4_q2_hours_allchild
replace s4_q2_hours_allchild_ag=. if childag==0
gen adultaghrs_ag=adultaghrs
replace adultaghrs_ag=. if childag==0
collapse (mean) adultaghrs s4_q2_hours_allchild adultaghrs_ag s4_q2_hours_allchild_ag, by(wave)

twoway	(line adultaghrs wave, color(gs8)) ///
		(line s4_q2_hours_allchild wave, lpattern(longdash) color(gs8)) ///
		(line adultaghrs_ag wave, color(black)) ///
		(line s4_q2_hours_allchild_ag wave, lpattern(longdash) color(black)) ///
		,  ///
		ytitle("Hours of household ag work in last 7 days", axis(1) size(medsmall) ) ///
		xtitle("") ///
		ylabel(0(10)80, labsize(medsmall) angle(0) grid glcolor(gs15)) ///
		xlabel(1 "2020 May-Jul" 2 "Jul-Sep" 3 "Oct-Nov" 4 "2021 Jan-Mar" 5 "Apr-Jun" 6 "Jul-Oct", labsize(medsmall)) ///
		text(70 3 "All HH adults - any child labor HHs" , color(black) size(medsmall) placement(n)) ///
		text(50 2 "All HH adults - all ag HHs" , color(gs8) size(medsmall) placement(s)) ///
		text(24 3 "All HH children - any child labor HHs" , color(black) size(medsmall) placement(n)) ///
		text(10 2 "All HH children - all ag HHs" , color(gs8) size(medsmall) placement(n)) ///
		text(0 1.5 "Schools closed" , color(black) size(medsmall) placement(n)) ///
		text(0 3 "| Schools partially reopen |" , color(black) size(medsmall) placement(n)) ///
		text(0 5 "Schools fully reopen" , color(black) size(medsmall) placement(n)) ///
		legend(off) 
graph export "$output/Graphs/hh_ag_wave.pdf", replace
graph export "$output/Graphs/hh_ag_wave.tif", replace
}

/////////
// Figure 3 Mean respondent work hours by treatment group over time
/////////
{
use "$data/indivs_merge.dta", clear
replace trt_ctl=. if grade12_hh>0
gen monum=month
keep if age>17
keep if inlist(wave,0,1,2,3,4)
gen period =wave
replace period=2 if wave==3 & post==0
lab def pd 0 "Feb" 1 "May-July" 2 "Aug-Oct 11" 3 "Oct 12-Nov" 4 "Jan-Mar"
la val period pd
ta period
replace monum=729 if monum==800 // had split October into two FEs, used 800 as placeholder value
ta monum
gen t=monum+post
replace t=t-724
replace t=t+1 if today>22141 & month==727
recode t 0=1 2=3 4=5 6=7 -3=-1 10=9 11=9
ta t month if !missing(trt_ctl)
lab def tmo -1 "Feb" 1 "May-Jun" 3 "Jul-Aug 15" 5 "Aug 16-Oct 11" 7 "Oct 12-Nov" 9 "Jan-Mar"
la val t tmo
keep if !missing(trt_ctl)
gen one=1 if inlist(wave,1,2,3) & resp==1
egen ct=sum(one),by(id)
drop if ct<2 & inlist(wave,1,2,3)

preserve 
keep if resp==1
collapse (mean) workl7=workinghrs_l7 (sd) sd=workinghrs_l7 (count) n=workinghrs_l7, by(trt_ctl t)
gen hi=workl7 + invttail(n-1,0.025)*(sd/sqrt(n))
gen lo=workl7 - invttail(n-1,0.025)*(sd/sqrt(n))
	
twoway 	(line workl7 t if trt_ctl==1, color(black)) ///
		(rcap hi lo t if trt_ctl==1, color(black)) ///
		(line workl7 t if trt_ctl==0, color(gs8) lpattern(dash)) ///
		,  ///	
		xtitle("", size(small)) ytitle("Total work hours in last 7 days", size(medsmall)) ///
		ylabel(0(5)35, labsize(medsmall) angle(0) nogrid) ///
		xlabel(-1(2)10, valuelabels labsize(medsmall) angle(0)) ///
		xline(0, lcolor(red)) xline(6, lcolor(red)) xline(8, lcolor(red))  ///
		text(34 -0.5 "Schools" "open" , color(black) size(medsmall) placement(s)) ///
		text(34 3 "Schools fully" "closed" , color(black) size(medsmall) placement(s)) ///
		text(34 7 "Schools" "partially" "reopen" , color(black) size(medsmall) placement(s)) ///
		text(34 9 "Schools" "fully" "reopen" , color(black) size(medsmall) placement(s)) ///
		text(24 2 "Treatment" , color(black) size(medsmall) placement(n)) ///
		text(18 2 "Control" , color(gs8) size(medsmall) placement(s)) ///
		legend(off) 
restore
graph export "$output/Graphs/hours_mean_wave_resp.pdf",replace	
graph export "$output/Graphs/hours_mean_wave_resp.tif",replace	
}

/////////
// Figure A1 Kenya COVID-19 Cases and timeline
/////////
{
* This code produces the line graph in the Figure A1 timeline
* The remaining elements on the graph were added manually in Powerpoint
import delimited using "$data/time_series_covid19_confirmed_global.csv", clear
keep if countryregion=="Kenya"
drop provincestate lat v4-v43 v440-v500
forvalues i=439(-1)45 {
	local j=`i'-1
	replace v`i'=v`i'-v`j'
}
reshape long v, i(countryregion) j(date)
gen day="March 1, 2020"
gen day2=date(day, "MDY")
replace date=date-44+day2
format date %td
ta date

gen week=wofd(date)
ta week
format week %tw

preserve
collapse (sum) v, by(week)
local white 	plotregion(color(white)) graphregion(color(none)) bgcolor(white)
twoway 	(line v week, color(black)), `white' ///
		ytitle("", axis(1) size(medsmall) ) ///
		ylabel(, labsize(medsmall) angle(0)) ///
		yscale(axis(1) lcolor(black)) /// 
		xtitle("", size(medsmall)) ///
		xline(3130, lc(black)) xline(3160, lc(black)) xline(3172, lc(black)) ///
		xlabel(3128(4)3184, angle(45)) ///
		legend(off) 
graph export "$output/Graphs/Covid_case_timeline.png",replace
restore
}

/////////
// Figure A2 Childcare arrangements when children are out of school
/////////
{
use "$data/indivs_merge.dta", clear
keep if wave>0

egen s3_q12b_wherenoschool_else=rowtotal(s3_q12b_wherenoschool_6 s3_q12b_wherenoschool_7)
replace s3_q12b_wherenoschool_else=1 if s3_q12b_wherenoschool_else>1 & !missing(s3_q12b_wherenoschool_else)
replace s3_q12b_wherenoschool_else=. if missing(s3_q12b_wherenoschool_1)

foreach var of varlist s3_q12b_wherenoschool_* {
	egen `var'_max=max(`var'),by(id wave)
	gen `var'_39=`var' if grade>=3 & grade<=9
	egen `var'_39m=max(`var'_39),by(id wave)
}
* Note distribution of locations looks identical if using only info for children in grades 3-9

preserve
keep if resp==1 & !missing(trt_ctl)
keep if wave<4
lab def waveshort 1 "Wave 1: May-July" 2 "Wave 2: July-Sep" 3 "Wave 3: Sep-Nov" 4 "Wave 4: Jan-Mar"
la values wave waveshort
local white 	plotregion(color(white)) graphregion(color(white)) bgcolor(white)
graph bar s3_q12b_wherenoschool_1_max s3_q12b_wherenoschool_2_max s3_q12b_wherenoschool_3_max s3_q12b_wherenoschool_4_max ///
	s3_q12b_wherenoschool_5_max s3_q12b_wherenoschool_else_max, over(wave, label(labsize(small)))	///
	ylabel(, angle(0) nogrid labsize(medsmall)) ///
	ytitle("Share of households", size (medsmall)) ///
	legend(label(1 "Home with parent") label(2 "Home with other adult") label(3 "Home by themselves") ///
	label(4 "Outside home with adult") label(5 "At work with adult") label(6 "Somewhere else") col(2) size(medsmall)) ///
	`white' 
graph export "$output/Graphs/Child_staying_anl.pdf", replace
graph export "$output/Graphs/Child_staying_anl.tif", replace
set scheme s2mono
local white 	plotregion(color(white)) graphregion(color(white)) bgcolor(white)
graph bar s3_q12b_wherenoschool_1_max s3_q12b_wherenoschool_2_max s3_q12b_wherenoschool_3_max s3_q12b_wherenoschool_4_max ///
	s3_q12b_wherenoschool_5_max s3_q12b_wherenoschool_else_max, over(wave, label(labsize(small)))	///
	ylabel(, angle(0) nogrid labsize(medsmall)) ///
	ytitle("Share of households", size (medsmall)) ///
	legend(label(1 "Home with parent") label(2 "Home with other adult") label(3 "Home by themselves") ///
	label(4 "Outside home with adult") label(5 "At work with adult") label(6 "Somewhere else") col(2) size(medsmall)) ///
	`white' 
graph export "$output/Graphs/Child_staying_anl_bw.tif", replace 
set scheme s1color
restore
}

/////////
// Figure A3 Mean respondent childcare hours by treatment group and sex over time
/////////
{
use "$wb_clean/indivs_merge.dta", clear
gen monum=month
keep if resp==1
keep if inlist(wave,0,1,2,3,4)
gen period =wave
replace period=2 if wave==3 & post==0
lab def pd 0 "Feb" 1 "May-July" 2 "Aug-Oct 11" 3 "Oct 12-Nov" 4 "Jan-Mar"
la val period pd
ta period
replace trt_ctl=. if grade12_hh>0
keep if !missing(trt_ctl)
replace trt_ctl=. if grade12_hh>0
gen one=1 if inlist(wave,1,2,3)
egen ct=sum(one),by(id)
drop if ct<2 & inlist(wave,1,2,3)
replace childcare_hr_pre=0 if missing(childcare_hr_pre) & wave==4
gen kidcount=kids_count
foreach v of varlist childcare_hr  {
	replace `v'=140 if `v'>140 & !missing(`v')
	replace `v'=0 if kidcount==0
}
egen childcare_hr_precl=max(childcare_hr_pre),by(id individual)
replace childcare_hr=childcare_hr_precl if !missing(childcare_hr_precl) & wave==0

collapse (mean) workl7=childcare_hr (sd) sd=childcare_hr (count) n=childcare_hr, by(gender trt_ctl period)
gen hi=workl7 + invttail(n-1,0.025)*(sd/sqrt(n))
gen lo=workl7 - invttail(n-1,0.025)*(sd/sqrt(n))
	
twoway 	(line workl7 period if trt_ctl==1 & gender==1, color(black)) ///
		(rcap hi lo period if trt_ctl==1 & gender==1, color(black)) ///
		(line workl7 period if trt_ctl==0 & gender==1, color(black) lpattern(dash)) ///
		(line workl7 period if trt_ctl==1 & gender==0, color(gs8)) ///
		(rcap hi lo period if trt_ctl==1 & gender==0, color(gs8)) ///
		(line workl7 period if trt_ctl==0 & gender==0, color(gs8) lpattern(dash)) ///
		,  ///	
		xtitle("", size(small)) ytitle("Respondent childcare hours in last 7 days", size(medsmall)) ///
		ylabel(0(10)70, labsize(medsmall) angle(0) nogrid) ///
		xlabel(, valuelabels labsize(medsmall) angle(1)) ///
		xline(2.5, lcolor(red)) xline(0.5, lcolor(red)) xline(3.5, lcolor(red))  ///
		text(70 0.2 "Schools" "open" , color(black) size(medsmall) placement(s)) ///
		text(70 1.5 "Schools fully" "closed" , color(black) size(medsmall) placement(s)) ///
		text(70 3 "Schools partially" "reopen" , color(black) size(medsmall) placement(s)) ///
		text(70 3.8 "Schools" "fully" "reopen" , color(black) size(medsmall) placement(s)) ///
		legend(order(1 "Treatment Women" 3 "Control Women" 4 "Treatment Men" 6 "Control Men" ) ///
		ring(0) position(6) bmargin(large))
graph export "$output/Graphs/cc_mean_wave_resp.pdf",replace	
graph export "$output/Graphs/cc_mean_wave_resp.tif",replace	
}	

/////////
// Figure A4 Mean child hours in household agricultural work by grade, randomly selected children in survey round 3
/////////
{
use "$data/indivs_merge.dta", clear

* Child ag descriptives
ta ag_hh if !missing(trt_ctl) & inlist(wave,1,2) & resp==1
ta anychildlabor if !missing(trt_ctl) & inlist(wave,1,2) & resp==1 & ag_hh==1
su s4_q2_hours_allchild if !missing(trt_ctl) & inlist(wave,1,2) & resp==1 & ag_hh==1
su s4_q2_hours_allchild if !missing(trt_ctl) & inlist(wave,1,2) & resp==1 & anychildlabor==1

ta ag_hh if  inlist(wave,1,2) & resp==1 & s2_q15b_schoolchildren>0
ta anychildlabor if inlist(wave,1,2) & resp==1 & ag_hh==1 & s2_q15b_schoolchildren>0
su s4_q2_hours_allchild if  inlist(wave,1,2) & resp==1 & s2_q15b_schoolchildren>0 & ag_hh==1 
su s4_q2_hours_allchild if  inlist(wave,1,2) & resp==1 & s2_q15b_schoolchildren>0 & anychildlabor==1

* Figure
keep if wave==3
keep if !missing(grade)
replace s4_q2_hours_allchild=0 if missing(s4_q2_hours_allchild)
gen anychildlabor=s4_q2_hours_allchild>0
replace anychildlabor=. if missing(s4_q2_hours_allchild)
egen anychildag=max(anychildlabor),by(id)

preserve
collapse (mean) s3_hh_farm_b, by(grade)
graph bar s3_hh_farm_b, over(grade, label(angle(0))) ///
    bar(1, color(gs8)) ///
    ytitle("Hours in last 7 days") ///
    blabel(bar, format(%9.2f)) ylabel(0(2)10,angle(0)) 
graph export "$output/Graphs/childag_mean_grade_all.pdf",replace	
graph export "$output/Graphs/childag_mean_grade_all.tif",replace	
restore

preserve
keep if anychildag==1

gen grade48=0 if inlist(grade,3,4,5,6,7,8,9)
replace grade48=1 if inlist(grade,4,8)
su s3_hh_farm_b if grade48==0 // 10.21
su s3_hh_farm_b if grade48==1 // 7.02
reg s3_hh_farm_b grade48 if anychildag==1 // -3.19 (p=0.054)
disp 3.2/10.2 // 31.4

collapse (mean) s3_hh_farm_b, by(grade)
graph bar s3_hh_farm_b, over(grade, label(angle(0))) ///
    bar(1, color(gs8)) ///
    ytitle("Hours in last 7 days") ///
    blabel(bar, format(%9.2f)) ylabel(,angle(0)) 
graph export "$output/Graphs/childag_mean_grade_anychildag.pdf",replace	
graph export "$output/Graphs/childag_mean_grade_anychildag.tif",replace	
restore
}

/////////
// Table A1. Comparison of analysis sample to other survey households
/////////
{
use "$data/indivs_merge.dta", clear
preserve
drop if wave<1
gen first=0
bysort uniqueindiv (wave): replace first=1 if _n==1
keep if first==1
keep if resp==1
gen sample=!missing(trt_ctl)
ta trt_ctl 

local statvars head_gender current_num_adults kids_ct any_ygkid ///
	wealth_index_norm urban ag_hh childag s4_q2_hours_allchild ent_hh ///
	age gender ed_prim ed_sec married ///
	working_l7 whoemployed_ hhag hhent workinghrs_l7 hoursnow agri_hrs enter_hrs childcare_hr
eststo clear
eststo all: estpost tabstat `statvars', statistics(mean sd) columns(statistics)
eststo kids: estpost tabstat `statvars' if kids==1, statistics(mean sd) columns(statistics)
eststo sample: estpost tabstat `statvars' if sample==1, statistics(mean sd) columns(statistics)
eststo childag: estpost tabstat `statvars' if anychildag==1, statistics(mean sd) columns(statistics)
eststo schildag: estpost tabstat `statvars' if anychildag==1 & sample==1, statistics(mean sd) columns(statistics)
esttab all kids sample childag schildag using "$output/Tables/sumstats.tex", ///
	nomtitle label end( \\ ) replace booktabs f ///
	refcat(head_gender "\textit{Household characteristics}" age "\textit{Respondent characteristics}", nolabel ) ///
	cells("mean(fmt(2))" "sd(par fmt(2))" ) 
restore
}

/////////
// Table A2. Baseline balance by treatment status
/////////
{
use "$data/indivs_merge.dta", clear
gen r3pre=(wave==3 & post==0)
egen r3_pre=max(r3pre),by(id)
drop if wave<1

gen one=1
replace one=0 if resp==0
replace one=0 if !inlist(wave,1,2,3)
egen prepostobs=sum(one), by(id post)

gen first=0
bysort uniqueindiv (wave): replace first=1 if _n==1
keep if first==1
keep if resp==1
keep if !missing(trt_ctl)

ta prepostobs 
ta trt_ctl if inlist(prepostobs,0,3)
disp 273/1590

gen otherkids=kids_ct-grade_39_ct
gen anyotherkids=otherkids>1
replace anyotherkids=. if missing(otherkids)
bys trt_ctl: su otherkids anyotherkids
su otherkids anyotherkids if !missing(trt_ctl)

global hhctl head_gender current_num_adults kids_ct any_ygkid ///
	wealth_index_norm urban ag_hh childag s4_q2_hours_allchild ent_hh
global indctl age gender ed_prim ed_sec married 
local statvars $hhctl $indctl working_l7 whoemployed_ hhag hhent  workinghrs_l7 hoursnow agri_hrs enter_hrs childcare_hr 
su `statvars' if !missing(trt_ctl)

reg trt_ctl `statvars' if trt_ctl!=2 // F=0.92, p=.576
reg trt_ctl `statvars' if trt_ctl!=1 // F=8.49, p=.000

eststo clear
eststo c1: corr_table_reg `statvars', indvar(trt_ctl) cluster() conditionals(if trt_ctl!=2)
eststo c2: corr_table_reg `statvars', indvar(trt_ctl) cluster() conditionals(if trt_ctl!=1) 
esttab c1 c2  using "$output/Tables/ttest_balance.tex", replace ///
		cells("mean(fmt(%9.2f) pattern(1 0))  b(star fmt(%9.2f))"  ///
        "sd(par fmt(%9.2f) pattern(1 0)) se(par fmt(%9.2f))") ///
		 label collabels(none) varwidth(55) nonum nonotes se noobs wrap nomtitles star(* 0.10 ** 0.05 *** 0.01) ///
		 mgroups(" \shortstack{Control (N=919) \\ Mean \\ (SD)} & \shortstack{Treated (N=323) \\ Difference \\ (SE)}  &  \shortstack{Mixed (N=348) \\ Difference  \\(SE)} " span) ///
		refcat(head_gender "\textit{Household characteristics}" age "\textit{Respondent characteristics}" working_l7 "\textit{Respondent labor supply}", nolabel)
}

/////////
// Table A3. Correlates of sample household characteristics
/////////
{
use "$data/indivs_merge.dta", clear
gen r3pre=(wave==3 & post==0)
egen r3_pre=max(r3pre),by(id)
drop if wave<1

gen one=1
replace one=0 if resp==0
replace one=0 if !inlist(wave,1,2,3)
egen prepostobs=sum(one), by(id post)

gen first=0
bysort uniqueindiv (wave): replace first=1 if _n==1
keep if first==1
keep if resp==1
keep if !missing(trt_ctl)

eststo clear
eststo: reg wealth_0 i.trt_ctl head_gender current_num_adults kids_ct any_ygkid urban ag_hh anychildag ent_hh
	su wealth_0 if e(sample)
	estadd scalar Mean = r(mean)
eststo: reg anychildag i.trt_ctl  wealth_0 head_gender current_num_adults kids_ct any_ygkid urban ag_hh ent_hh 
	su anychildag if e(sample)
	estadd scalar Mean = r(mean)
esttab using "$output/Tables/correlates_hhchars.tex", ///
	scalars("Mean Outcome mean") /// 
	mlabels("\shortstack{Above \\ mean \\ HH wealth }" "\shortstack{Any child \\ HH ag work}" ) ///		
	star(* 0.10 ** 0.05 *** 0.01) drop(_cons) ///
	addnote("SEs clustered at household level.") ///
	b(3) se(3) varwidth(45) num nonotes label replace booktabs nobaselevels obs f end( \\ )
}




